---
title: Hugging Face Transformers.js
date: 2024-12-02
authors: pelikhan
tags:
  - LLM
  - SLM
  - transformers
  - Hugging Face
  - JavaScript
canonical_url: https://microsoft.github.io/genaiscript/blog/hugging-face-transformers
description: Learn how to run LLMs locally using Hugging Face Transformers.js in
  GenAIScript, enabling you to leverage powerful language models in your
  JavaScript projects.
cover:
  alt: An 8-bit style image displays various technology icons symbolizing
    JavaScript, transformers, and AI. These icons are integrated into an
    arrangement of abstract geometric shapes that represent a browser and server
    environment. The image is simplified using a 5-color palette, maintaining a
    consistent and coherent aesthetic. No people or text are present.
  image: ./hugging-face-transformers.png
excerpt: Hugging Face Transformers.js brings large language models to your
  browser or Node.js environment, enabling text generation tasks entirely
  locally. With GenAIScript integration, configuring and caching models is
  straightforward, letting you tap into a wide range of options or fine-tune
  your own. Explore new ways to harness LLMs efficiently and seamlessly.

---

import BlogNarration from "../../../components/BlogNarration.astro"

<BlogNarration />

<p style="text-align:center">
    <span style="font-size: 12rem;">🤗</span>
</p>

:::caution

We have temporarily removed support for the `transformers` model provider in GenAIScript to reduce
the installation footprint.

:::

[Hugging Face Transformers.js](https://huggingface.co/docs/transformers.js/index)
is a JavaScript library that provides a simple way to run LLMs in the browser or node.js (or Bun, Deno, ...).


```js 'model: "transformers:HuggingFaceTB/SmolLM2-1.7B-Instruct:q4f16"'
script({
    model: "transformers:HuggingFaceTB/SmolLM2-1.7B-Instruct:q4f16",
})
```

GenAIScript will download and cache the model for you, and you can start using it right away
**fully locally**.

There are [plenty of models](https://huggingface.co/models?pipeline_tag=text-generation&library=transformers.js) to choose from and you can also follow the Hugging Face documentation to fine tune your own.
